#include "ProjectionMatrix.hpp"
#include "HDRDemoConstants.hpp"

ProjectionMatrix::ProjectionMatrix(GLdouble& fov, GLdouble& aspect, GLdouble& nearPlane, GLdouble& farPlane)
{
	m_fov = fov * PI/180.0;
	m_farClipPlane = farPlane;
	m_nearClipPlane = nearPlane;
	m_aspect = aspect;

	GLdouble f = cos( m_fov/(GLdouble)2.0 )/sin( m_fov/(GLdouble)2.0 );

	GLdouble fac1 = ( farPlane + nearPlane )/( nearPlane - farPlane );
	GLdouble fac2 = ( 2 * farPlane * nearPlane )/( nearPlane - farPlane );

	m_projectionMatrix = MMatrix4( f/aspect, 0, 0, 0,
		                                  0, f, 0, 0,
										  0, 0, fac1, fac2,
										  0,    0,   -1, 0 );

	m_projectionMatrix.TransposeMatrix();
}

ProjectionMatrix::ProjectionMatrix(GLdouble fov, GLdouble aspect, GLdouble nearPlane, GLdouble farPlane)
{
	m_fov = fov * PI/180.0;
	m_farClipPlane = farPlane;
	m_nearClipPlane = nearPlane;
	m_aspect = aspect;

	GLdouble f = cos( m_fov/2.0 )/sin( m_fov/2.0 );

	GLdouble fac1 = ( farPlane + nearPlane )/( nearPlane - farPlane );
	GLdouble fac2 = ( 2 * farPlane * nearPlane )/( nearPlane - farPlane );

	m_projectionMatrix = MMatrix4( f/aspect, 0, 0, 0,
		                                  0, f, 0, 0,
										  0, 0, fac1, fac2,
										  0,    0,   -1, 0 );

	m_projectionMatrix.TransposeMatrix();
}

ProjectionMatrix::~ProjectionMatrix()
{
}

const MMatrix4& ProjectionMatrix::GetProjectionMatrix() const
{
	return m_projectionMatrix;
}